package com.bsj.power.job.web.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.bsj.power.common.config.exception.ApiException;
import com.bsj.power.common.config.global.JsonResult;
import com.bsj.power.common.config.global.JsonResultEnum;
import com.bsj.power.common.def.dto.PageDTO;
import com.bsj.power.common.def.dto.job.ExperienceDTO;
import com.bsj.power.common.def.dto.job.LearnDTO;
import com.bsj.power.common.def.entity.exp.Experience;
import com.bsj.power.common.def.entity.exp.Learn;
import com.bsj.power.job.service.LearnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yinhao
 * @version 1.0
 * @description 知识库
 * @date 2024/7/3
 */
@RestController
@RequestMapping("/learn")
//@SaCheckPermission("/job/learn")
public class LearnController {

    @Autowired
    private LearnService learnService;

    /**
     * 添加知识库
     * @param dto
     * @return
     */
    @PostMapping("/doAddAndUpdateLearn")
    public JsonResult doAddAndUpdateLearn(@RequestBody LearnDTO dto) throws Exception{
        return learnService.addAndUpdate(dto);
    }

    /**
     * 获取知识库列表
     * @param dto
     * @return
     */
    @GetMapping("/doLearnPageList")
    public JsonResult<List<Learn>> doExpPageList(PageDTO dto, String title) {
        return learnService.pageList(dto, title);
    }

    /**
     * 根据ID或取知识库
     * @param learnId
     * @return
     */
    @GetMapping("/doLearnFindIdByInfo")
    public JsonResult<Learn> doExpFindIdByInfo(Long learnId) {
        if (learnId == null) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        return learnService.findIdByInfo(learnId);
    }

    /**
     * 批量删除知识库
     * @param dto
     * @return
     */
    @PostMapping("/doDeleteByIdLearn")
    public JsonResult<Integer> doDeleteByIdExp(@RequestBody LearnDTO dto) {
        Long[] learnIds = dto.getLearnIds();
        if (learnIds == null) {
            throw new ApiException(JsonResultEnum.PARAM_ERROR);
        }
        return learnService.deleteByIds(learnIds);
    }
}
